<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>微分享-后台管理系统</title>
    <meta name="description" content="微分享-后台管理系统"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" th:href="@{/static/img/favicon.ico}" />
    <link rel="stylesheet" th:href="@{/static/assets/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/static/assets/css/admin.css}"/>
    <link rel="stylesheet" th:href="@{/static/lib/layer/skin/layer.css}" />
    <script th:src="@{/static/assets/js/jquery.min.js}"></script>
    <script th:src="@{/static/assets/js/amazeui.min.js}"></script>
    <script th:src="@{/static/assets/js/app.js}"></script>
    <script th:src="@{/static/js/public.js}"></script>
	<script type= "text/javascript" th:src ="@{/static/lib/layer/layer.js}"></script>   
	<script type= "text/javascript" th:src ="@{/dwr/util.js}"></script>   
	<script type="text/javascript" th:src= "@{/dwr/engine.js}"></script > 
	<script type="text/javascript" th:src= "@{/dwr/interface/NoticeContentController.js}"></script>
	<script type="text/javascript" th:src= "@{/static/js/dwrhelp.js}"></script>
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
    以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-topbar-brand">
        <strong>微分享</strong>
        <small>后台管理系统</small>
    </div>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li class="am-dropdown" id="am-dropdown">
                <a class="am-dropdown-toggle"  data-am-dropdown='' href="javascript:;">
                    <span class="am-icon-users"></span> 管理员<span th:text="${session.userName}"></span><span class="am-icon-caret-down"></span>
                </a>
		        <ul class="am-dropdown-content">
		          <li><a th:href="@{/admin-user}"><span class="am-icon-user"></span> 资料</a></li>
		          <li><a href="logout"><span class="am-icon-power-off"></span> 退出</a></li>
		        </ul>
            </li>
            <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span
                    class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>
        </ul>
    </div>
</header>

<div class="am-cf admin-main">
    <!-- sidebar start -->
    <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
        <div class="am-offcanvas-bar admin-offcanvas-bar">
            <ul class="am-list admin-sidebar-list">
                <li><a href="admin_index"><span class="am-icon-home"></span>内容管理</a></li>
                <li><a href="admin_users"><span class="am-icon-table"></span>用户管理</a></li>
                <li><a href="admin_add_pictureshare"><span class="am-icon-table"></span>添加分享</a></li>
				<li><a href="register"><span class="am-icon-table"></span>管理员注册</a></li>
                <li><a href="logout"><span class="am-icon-sign-out"></span> 注销</a></li>
            </ul>

            <div class="am-panel am-panel-default admin-sidebar-panel">
                <div class="am-panel-bd">
                    <p><span class="am-icon-bookmark"></span> 公告</p>
                    <p>时光静好，与君语；细水流年，与君同。</p>
                </div>
            </div>
        </div>
    </div>
    <!-- sidebar end -->

	<div id="jBox1" class="jBox-wrapper jBox-Notice jBox-NoticeBorder jBox-hasTitle jBox-Notice-color jBox-Notice-red" style="position: fixed; z-index: 10000; right: 36px; bottom: 100px; display: none; opacity: 1;">
		<div class="jBox-closeButton jBox-noDrag"></div>
		<div class="jBox-container" style="width: auto; height: auto;">
			<!-- <div class="jBox-title"><div id="noticePublicTime">2016-05-30</div></div> -->
			<div class="jBox-content"></div>
		</div>
		<div><input type="button" value="关闭" id="closeBtn"/></div>
	</div>

    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding">
                <div class="am-fl am-cf">
                    <strong class="am-text-primary am-text-lg">内容管理</strong>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
		          <div class="am-form-group">
		            <select data-am-selected="{btnSize: 'sm'}" id="order">
		              <option value="0">默认</option>
		              <option value="1">时间排序</option>
		              <option value="2">评论数排序</option>
<!-- 		              <option value="3">时间和评论数排序</option> -->
		            </select>
		          </div>
        		</div>
		         <div style="float: left" class="am-u-sm-12 am-u-md-3">
			          <div class="am-input-group am-input-group-sm">
			            <input type="text" class="am-form-field"  id="condition"/>
				          <span class="am-input-group-btn">
				            <button class="am-btn am-btn-default" onclick="search()" type="button">搜索
				            </button>
				          </span>
			          </div>   
			          <div class="am-input-group am-input-group-sm">
				          <span id="search_result" style="color: red"></span>
			          </div>
		         </div>
       		</div>

            <ul class="am-avg-sm-1 am-avg-md-4 am-margin am-padding am-text-center admin-content-list ">
                <li><a href="#" class="am-text-warning"><span
                        class="am-icon-btn am-icon-briefcase"></span><br/>分享数<br/><span
                        id="totalShare"></span></a>
                </li>
                <li><a href="#" class="am-text-warning"><span
                        class="am-icon-btn am-icon-briefcase"></span><br/>图片数<br/><span
                        id="imageNum"></span></a>
                </li>
                <li><a href="#" class="am-text-danger"><span
                        class="am-icon-btn am-icon-recycle"></span><br/>评论数<br/><span
                        id="commentNum"></span></a>
                </li>
                <li><a href="#" class="am-text-secondary"><span
                        class="am-icon-btn am-icon-user-md"></span><br/>用户数<br/><span
                        id="userNum"></span></a>
                </li>
            </ul>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <table class="am-table am-table-striped am-table-hover table-main">
                        <thead>
                        <tr>
                            <th>用户名</th>
                            <th>创建时间</th>
                            <th>信息</th>
                            <th>评论数</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="content">

                        </tbody>
                    </table>
                    <div class="am-cf">
                        共 <span id="total_item"></span> 条记录
                        <div class="am-fr">
                            <ul class="am-pagination" id="pageContent">

                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <footer class="admin-content-footer">
                <p class="am-padding-left">周航@成都信息工程大学, All Rights Reserved.</p>
            </footer>
        </div>
        <!-- content end -->

    </div>

    <a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu"
       data-am-offcanvas="{target: '#admin-offcanvas'}"></a>
    <script>
    /*<![CDATA[*/
     	postReturnJson("/admin/sys_report",{},function (msg) {
            if (msg.code == 401) {
                alert("请先登陆");
                window.location.href = 'login';
            } else {
                var json = msg.result;
                $("#imageNum").text(json.imageNum);
                $("#commentNum").text(json.commentNum);
                $("#userNum").text(json.userNum);
                $("#totalShare").text(json.pictureShareNum);
                $("#total_item").text(json.pictureShareNum);

                var totalNum = json.pictureShareNum;
                var pageSize = 10;
                var N = 0;
                if (totalNum % pageSize == 0) {
                    N = parseInt(totalNum / pageSize);
                } else {
                    N = parseInt(totalNum / pageSize) + 1;
                }
                //alert(parseInt(N));
                for (var i = 0; i < N; i++) {
                    $("#pageContent").append("<li onclick='getPage(" + parseInt(i + 1) + ",10)' class=\"#\"><a href=\"#\">" + parseInt(i + 1) + "</a></li>");
                }
            }
         });
        getPage(1, 10);

        function getPage(pageNo, pageSize) {
            $.ajax({
                url:"/picture_share_list",
                data: {
                    pageSize: pageSize,
                    pageNo: pageNo
                },
                success: function (msg) {
                	console.info(msg);
                   if (msg.code == true) {
                        var json = msg.result;
                        $("#content").empty();
                        $("#content").append("<tbody id=\"content\">");
                        for (var i = 0; i < json.length; i++) {
                            $("#content").append("<tr>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"'  style=\"width: 10%\">" + json[i].userName + "</td>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"'  style=\"width: 10%\">" + json[i].createdOn + "</td>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"' style=\"width: 10%\">" + json[i].remark.substr(0, 10) + "</td>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"' style=\"width: 10%\">" + json[i].commentDtoList.length + "</td>\n" +
                                    "                            <td  style=\"width: 20%\">" + "<div class=\"am-btn-group am-btn-group-xs\"><button onclick='deletePicutureShare(" + json[i].id + ")' class=\"am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only\"><span class=\"am-icon-trash-o\"></span> 删除</button><button onclick='makeTop(" + json[i].id + ")' class=\"am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only\"><span class=\"am-icon-pencil-square-o\"></span> 置顶</button><button onclick='deleteTop(" + json[i].id + ")' class=\"am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only\"><span class=\"am-icon-pencil-square-o\"></span>取消置顶</button>" + "</div></td>\n" +
                                    "                        </tr>");
                        }
                        $("#content").append("</tbody>");
                    }
                }
            });
        }

        function deletePicutureShare(id) {
            $.ajax({
            	type : 'POST',
            	url: "/delete_Share/" + id,
                success: function (msg) {
                    if (msg == 'true') {
                        alert('删除成功');
                        window.location.reload();
                    }
                }
            });
        }
        
        function makeTop(id) {
            $.ajax({
            	type : 'POST',
            	url: "/makeTop/" + id,
                success: function (msg) {
                    if (msg == 'true') {
                        alert('置顶成功');
                        window.location.reload();
                    }
                }
            });
        }
        
       function deleteTop(id) {
            $.ajax({
            	type : 'POST',
            	url: "/deleteTop/" + id,
                success: function (msg) {
                    if (msg == 'true') {
                        alert('取消置顶成功');
                        window.location.reload();
                    }
                }
            });
        }

        function search() {
        	var param = {
        		    condition: encodeURI($("#condition").val()),
                    order: $("#order").val()
        	};
            $.ajax({
                url:"/search",
                data:param,
                success: function (msg) {
                     if (msg.success) {
                        var json = msg.result;
                        $("#pageContent").empty();
                        $("#total_item").text(json.length);
                        $("#search_result").text("共搜索到：" + json.length + "条结果");
                        $("#content").empty();
                        $("#content").append("<tbody id=\"content\">");
                        for (var i = 0; i < json.length; i++) {
                            $("#content").append("<tr>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"'  style=\"width: 10%\">" + json[i].userName + "</td>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"'  style=\"width: 10%\">" + json[i].createdOn + "</td>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"' style=\"width: 10%\">" + json[i].remark.substr(0, 10) + "</td>\n" +
                                    "                            <td onclick='location.href=\"" + "detail?pictureShareId=" + json[i].id + "\"' style=\"width: 10%\">" + json[i].commentDtoList.length + "</td>\n" +
                                    "                            <td  style=\"width: 20%\">" + "<div class=\"am-btn-group am-btn-group-xs\"><button onclick='deletePicutureShare(" + json[i].id + ")' class=\"am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only\"><span class=\"am-icon-trash-o\"></span> 删除</button><button onclick='makeTop(" + json[i].id + ")' class=\"am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only\"><span class=\"am-icon-pencil-square-o\"></span> 置顶</button><button onclick='deleteTop(" + json[i].id + ")' class=\"am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only\"><span class=\"am-icon-pencil-square-o\"></span>取消置顶</button>" + "</div></td>\n" +
                                    "                        </tr>");
                        }
                        $("#content").append("</tbody>");
                    }
                }
            });
        }
        /*]]>*/
    </script>
</div>
</body>
</html>
